package bishi.baidu.two;

import java.util.Scanner;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/09/07 20:03
 */
public class one {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        while (n > 0) {
            n--;
            Long nums = sc.nextLong();
            String num = String.valueOf(nums);
            char[] chars = num.toCharArray();
            for (int i = chars.length - 1; i >= 0; i--) {
                int now = chars[i] - '0';
                if (i != 0 && now == 0) {
                    chars[i] = '3';
                    if (chars[i - 1] - '0' > 0) chars[i - 1]--;
                }
            }
            for (int i = 0; i < chars.length; i++) {
                int now = chars[i] - '0';
                if (now > 3) {
                    chars[i] = '3';
                }
            }
            String s = new String(chars);
            Long i = Long.parseLong(s);
            System.out.println(i);
//            if (s.charAt(0) == '0') s = s.substring(1);
//            System.out.println(s);
        }
    }
}
